import java.io.BufferedReader;
import java.io.FileReader;
import java.util.StringTokenizer;

public class Rectangle {

	public static void main(String[] args) throws Throwable {
		BufferedReader br = new BufferedReader(new FileReader("rectangle"));
		while (true) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			int n = Integer.parseInt(st.nextToken());
			int c = Integer.parseInt(st.nextToken());
			if(c==0&&n==0)break;
			int altura[][] = new int[n][n];
			boolean colores[][][] = new boolean[n][n][c + 1];
			st = new StringTokenizer(br.readLine());
			// alturas
			for (int i = 0, j = 0; i < altura.length; i++, j++) {
				altura[i][j] = Integer.parseInt(st.nextToken());
			}
			// colores
			st = new StringTokenizer(br.readLine());
			for (int i = 0, j = 0; i < colores.length; i++, j++) {
				colores[i][j][Integer.parseInt(st.nextToken())] = true;
			}
			// revisando intervalos

			for (int k = 1; k < n; k++) {
				for (int i = 0, j = k; i < n && j < n; i++, j++) {
					// para verificar si los colores estan completos
					if (colores[i][j - 1][c] || colores[i + 1][j][c]) {
						colores[i][j][c] = true;
					} else {
						boolean completos = true;
						for (int h = 0; h < c; h++) {
							colores[i][j][h] = colores[i][j - 1][h]
									|| colores[i + 1][j][h];
							if (!colores[i][j][h])
								completos = false;
						}
						colores[i][j][c] = completos;
					}
					//minimo altura para intervalo
					altura[i][j]=Math.min(altura[i+1][j], altura[i][j-1] );
				}
			}
			int res=Integer.MIN_VALUE;
			for (int i = 0; i < n; i++) {
				for (int j = i; j < n; j++) {
					if(colores[i][j][c]){
						res=Math.max(altura[i][j]*(j-i+1), res);
					}
				}
			}
			System.out.println(res);

		}
	}

}
